﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace WZ.ST.Site.Controllers
{
    public class DebugController : Controller
    {
        //
        // GET: /Debug/

        public ActionResult Index(string code = "000002")
        {

            //WZ.WebSpider.CompanySpider spider = new WZ.WebSpider.CompanySpider(
            //    "http://www.szse.cn/szseWeb/FrontController.szse"
            //    , @"(<tr>.+?<u>(?<Code>\d+)</u>.+<u>(?<SimplyName>.+)</u>(?!</tr>).)*"
            //    , Encoding.GetEncoding("GBK"));
            //return Json(spider.GetWebData(string.Format("ACTIONID=7&AJAX=AJAX-TRUE&CATALOGID=1110&tab1PAGENUM={0}&tab1PAGECOUNT=186&tab1RECORDCOUNT=1858&TABKEY=tab2", pageID)), JsonRequestBehavior.AllowGet);
            //WZ.WebSpider.StockMarketSpider spider = new WZ.WebSpider.StockMarketSpider(code);
            //List<WZ.Entity.StockMarket> market = spider.GetWebData("");
            //return Content(JsonConvert.SerializeObject(market[0]));
            return null;
        }
        //public ActionResult SpAllCommpanyLastMarketInfo()
        //{
        //    List<WZ.Entity.Commpany> companyList = new List<WZ.Entity.Commpany>();
        //    WZ.Stock.Data.CommpanyDAL dal = new WZ.Stock.Data.CommpanyDAL();
        //    WZ.Stock.Data.StockMarketDAL dalS = new WZ.Stock.Data.StockMarketDAL();
        //    companyList = dal.GetAllCompany();
        //    foreach (var item in companyList)
        //    {
        //        WZ.WebSpider.StockMarketSpider spider = new WZ.WebSpider.StockMarketSpider(item.Code);
        //        List<WZ.Entity.StockMarket> market = spider.GetWebData("");

        //        dalS.InsertData(market[0]);
        //        Thread.Sleep(1000);
        //    }
        //    return Content("1");
        //}
        public ActionResult GetAnnouncement(int pageNum = 1)
        {
            string urlParams = string.Format("stock=&searchkey=&plate=&category=&trade=&column=sse&columnTitle=%E6%B2%AA%E5%B8%82%E5%85%AC%E5%91%8A&pageNum={0}&pageSize=30&tabName=latest&sortName=&sortType=&limit=&showTitle=&seDate=%E8%AF%B7%E9%80%89%E6%8B%A9%E6%97%A5%E6%9C%9F", pageNum);
            WZ.WebSpider.AnnouncementSpider spider = new WZ.WebSpider.AnnouncementSpider();
            List<WZ.Entity.Announcement> market = spider.GetWebData(urlParams);
            return Json(market, JsonRequestBehavior.AllowGet);
        }
        public ActionResult GetClass()
        {
            //type:class industry area
            string type = Common.RequestHelper.GetString("type");
            WZ.WebSpider.dic_CompanyClassSpider spider = new WZ.WebSpider.dic_CompanyClassSpider();
            List<WZ.Entity.dic_CompanyClass> data = spider.GetWebData( type);
            return Json(data, JsonRequestBehavior.AllowGet);
        }

    }
}
